//
//  MyParticleEffect.m
//  ExampleAnimatingSprite
//
//  Created by admin on 3/20/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "MyParticleEffect.h"

@implementation MyParticleEffect
static int numParticleEffectMethods = 13;

-(CCParticleExplosion*) getParticleExplosionEffect {
	return [CCParticleExplosion node];
}
-(CCParticleFire*) getParticleFireEffect {
	return [CCParticleFire node];
}
-(CCParticleFireworks*) getParticleFireworksEffect {
	return [CCParticleFireworks node];
}
-(CCParticleFlower*) getParticleFlowerEffect {
	return [CCParticleFlower node];
}
-(CCParticleGalaxy*) getParticleGalaxyEffect {
	return [CCParticleGalaxy node];
}
-(CCParticleMeteor*) getParticleMeteorEffect {
	return [CCParticleMeteor node];
}
-(CCParticleRain*) getParticleRainEffect {
	return [CCParticleRain node];
}
-(CCParticleSmoke*) getParticleSmokeEffect {
	return [CCParticleSmoke node];
}
-(CCParticleSnow*) getParticleSnowEffect {
	return [CCParticleSnow node];
}
-(CCParticleSpiral*) getParticleSpiralEffect {
	return [CCParticleSpiral node];
}
-(CCParticleSun*) getParticleSunEffect {
	return [CCParticleSun node];
}
-(ParticleWaterfall*) getParticleWaterfallEffect {
	return [ParticleWaterfall node];
}
-(ParticleWaterSprinkler*) getParticleWaterSprinklerEffect {
	return [ParticleWaterSprinkler node];
}



- (CCLayer*) runRecipe
{
    particleEffectMethods = [[NSArray alloc] initWithObjects:@"ParticleExplosion",
                     @"ParticleFire",
                     @"ParticleFireworks",
                     @"ParticleFlower",
                     @"ParticleGalaxy",
                     @"ParticleMeteor",
                     @"ParticleRain",
                     @"ParticleSmoke",
                     @"ParticleSnow",
                     @"ParticleSpiral",
                     @"ParticleSun",
                     @"ParticleWaterfall",
                     @"ParticleWaterSprinkler", nil];
    
    currentEffect = 0;
    
    
    CCSprite *sprite = [CCSprite spriteWithFile:@"colorable_sprite.png"];
	[sprite setPosition:ccp(240,150)];
	[sprite setScale:2.0f];
	[self addChild:sprite z:0 tag:TAG_SPRITE_TO_EFFECT];
    
    [CCMenuItemFont setFontSize:16];
    
    CCMenuItemFont* prev = [CCMenuItemFont itemFromString:@"<PREV" 
                                                   target:self 
                                                 selector:@selector(prevEffectCallback:)];
    CCMenu* prevMenu = [CCMenu menuWithItems:prev, nil];
    prevMenu.position = ccp(160,20);
    [self addChild:prevMenu z:0 tag:TAG_PREV_EFFECT];
    
    CCMenuItemFont* reload = [CCMenuItemFont itemFromString:@"<RELOAD>" 
                                                     target:self 
                                                   selector:@selector(reloadEffectCallback:)];
    CCMenu* reloadMenu = [CCMenu menuWithItems:reload, nil];
    reloadMenu.position = ccp(240,20);
    [self addChild:reloadMenu z:0 tag:TAG_RELOAD_EFFECT];
    
    CCMenuItemFont* next = [CCMenuItemFont itemFromString:@"NEXT>" 
                                                   target:self 
                                                 selector:@selector(nextEffectCallback:)];
    CCMenu* nextMenu = [CCMenu menuWithItems:next, nil];
    nextMenu.position = ccp(320,20);
    [self addChild:nextMenu z:0 tag:TAG_NEXT_EFFECT];
    
    [self runCurrentEffect];
    return self;
}
-(void) prevEffectCallback:(id)sender {
	currentEffect -= 1;
	if(currentEffect < 0){
		currentEffect = numParticleEffectMethods-1;
	}
	[self removeChildByTag:TAG_EFFECT_NAME cleanup:YES];
	[self runCurrentEffect];
}
-(void) reloadEffectCallback:(id)sender {
	[self removeChildByTag:TAG_EFFECT_NAME cleanup:YES];
	[self runCurrentEffect];	
}
-(void) nextEffectCallback:(id)sender {
	currentEffect += 1;
	if(currentEffect >= numParticleEffectMethods){
		currentEffect = 0;
	}
	[self removeChildByTag:TAG_EFFECT_NAME cleanup:YES];
	[self runCurrentEffect];
}
-(void) runCurrentEffect {
    CCNode *node = [self getChildByTag:TAG_EFFECT_NODE];
	[node stopAllActions];
	[self removeChild:node cleanup:YES];
	
	NSString *method = [NSString stringWithFormat:@"get%@Effect",[particleEffectMethods objectAtIndex:currentEffect]];
	node = [self performSelector:NSSelectorFromString(method)];
	[self addChild:node z:1 tag:TAG_EFFECT_NODE];
	
	[node setPosition:ccp(240,160)];
	if( [[particleEffectMethods objectAtIndex:currentEffect] isEqualToString:@"ParticleWaterfall"] ||
       [[particleEffectMethods objectAtIndex:currentEffect] isEqualToString:@"ParticleRain"] ||
       [[particleEffectMethods objectAtIndex:currentEffect] isEqualToString:@"ParticleSnow"] ){
        [node setPosition:ccp(240,280)];
	}


}
@end
